package com.ecube.mqtt.page;
import org.junit.Test;

import javax.swing.*;
import java.awt.*;
public class Demo extends JFrame{


        public static void main(String[] args) {
            int stu = 20;
            System.out.println(getType(stu));
            System.out.println(getTestType(stu));
        }



        public static int getType(int stu) {
            if(stu>=1 & stu<=20){
                return 1;
            }else if (stu>=21 & stu<=40){
                return 2;
            }else if (stu>=41 & stu<=60){
                return 3;
            }else {
                return 0;
            }
        }

        public static String getTestType(int stu){
            int a =stu % 6;
            if(a==0){
                return "语句覆盖";
            }else if (a==1){
                return "判定覆盖";
            }else if (a==2){
                return "条件覆盖";
            }else if (a==3){
                return "判定/条件覆盖";
            }else if (a==4){
                return "组合覆盖";
            }else{
                return "路径覆盖";
            }

        }



        // 北部区域
        JLabel jl1;
        // 南部区域
        JButton login, quit, register;
        JPanel jp1;
        // 中部区域
        JTabbedPane jtp;// 选项卡
        JPanel jp2, jp3, jp4;
        JLabel jl2, jl3, jl4, jl5;
        JButton clear;
        JCheckBox jcb1, jcb2;
        Demo(){
            super();
            // 北部区域
            ImageIcon ic = new ImageIcon("./lib/hui.jpg");
            jl1 = new JLabel(ic);
            // 南部区域
            jp1 = new JPanel();
            login = new JButton("登录");
            quit = new JButton("取消");
            register = new JButton("注册");
            jp1.add(login);
            jp1.add(quit);
            jp1.add(register);

            jtp = new JTabbedPane();
            jp2 = new JPanel();
            jp3 = new JPanel();
            jp3.setBackground(Color.RED);
            jp4 = new JPanel();
            jp4.setBackground(new Color(0, 0, 255));

            // 将面板添加到选项卡窗格上
            jtp.add("QQ号码", new TestPane());
            jtp.add("手机号码", jp3);
            jtp.add("电子邮箱", jp4);
            this.add(jl1, BorderLayout.NORTH);
            this.add(jp1, BorderLayout.SOUTH);
            this.add(jtp);
            this.setVisible(true);

            this.setLocation(200, 200);

            this.setAlwaysOnTop(true);

            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            this.setResizable(false);

            this.pack();
            this.setTitle("腾讯QQ");
  }

    public class TestPane extends JPanel {

        public TestPane() {
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(600, 600);
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            Dimension dimTop = new Dimension(500, 40);
            JLabel labName1 = new JLabel("用户名:");
            super.add(labName1);
            Dimension dim = new Dimension(310, 30);

            JTextField user = new JTextField();
            user.setPreferredSize(dim);
            super.add(user);
            LineFeed(190);

            JLabel labName2 = new JLabel("密码:");
            super.add(labName2);
            JTextField pasword = new JTextField();
            pasword.setPreferredSize(dim);
            super.add(pasword);
//            Graphics2D g2d = (Graphics2D) g.create();
//            String text = getWidth() + "x" + getHeight();
//            FontMetrics fm = g2d.getFontMetrics();
//            int x = (getWidth() - fm.stringWidth(text)) / 2;
//            int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent();
//            g2d.drawString(text, x, y);
//
//            g2d.dispose();
        }
        private void LineFeed(int num) {

            String emptyString = "";
            for(int i=0; i<num; i++)    emptyString += " ";
            this.add(new JLabel(emptyString));
        }


    }

}
